package loadDataFromFile;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import pojo.Book;

public class StoreBooksToFile{
	public static void main(String[] args) {
		List<Book> list = new ArrayList<Book>();
		ObjectOutputStream out = null;
		try {
			out = new ObjectOutputStream(new FileOutputStream("test.txt"));
		} catch (Exception e) {
			System.out.println("打开流失败");
		}
		Book book = null;
		int id = 1;
		String name = "jordan";
		Date publishDate = new Date();
		String author = "tony";
		double price = 0;
		boolean isNew = true;
		String publisher = "nick";
		
		int i = 1;
		while(i <= 10000){
			book = new Book();
			book.setId(i);
			book.setName(name);
			book.setPublishDate(publishDate);
			book.setAuthor(author);
			book.setPrice(price);
			book.setNewOrOld(isNew);
			book.setPublisher(publisher);
			System.out.println(book.getId());
			i++;
			
			list.add(book);
		}
		try {
			out.writeObject(list);
			out.close();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
}
